package com.changgou.system;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.context.annotation.Bean;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
/**
 * @Author Tang
 * @Date 2020/9/11 18:37
 * @Description
 */
@SpringBootApplication
@EnableEurekaClient
public class GateWayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GateWayApplication.class, args);
    }
    /**
     * 创建Bean添加到Spring容器中
     * @return 秘钥解析器
     * 作用:对当前客户端IP进行限制
     */
    @Bean
    public KeyResolver ipKeyResolver() {
        return new KeyResolver() {
            @Override
            public Mono<String> resolve(ServerWebExchange exchange) {
                //对当前客户端(gateway_system)的访问IP地址进行限制,具体限制参数在配置文件中设置
                return Mono.just(exchange.getRequest().getRemoteAddress().getHostName());
            }
        };
    }
}
